/*
  IMPORTANT (otherwise, your code may not compile)	
  Same as using sqlplus, you need to set oracle environment variables by 
  sourcing bash.env or tcsh.env
*/

import tasks.*; // Our tasks
import java.io.Console; // Because it's easier than manually using the stream.  Also, it has printf!
import java.sql.*; // So that we can use SQL

public class UISkeleton {
    private Connection connection;
    private Statement statement;
    private ResultSet resultSet;
    private String query;
    private String username, password;

    private static Task[] task = {new Zero(),
                                  new One(),
                                  new Two(),
                                  new Three(),
                                  new Four(),
                                  new Five(),
                                  new Six(),
                                  new Seven(),
                                  new Eight(),
                                  new Nine(),
                                  new Ten(),
                                  new Eleven(),
                                  new Twelve(),
                                  new Thirteen()};

	public UISkeleton() {
        String input = null;
        int command = 0;
        Console c = System.console();
        if (c == null) {
            System.err.println("No console.");
            System.exit(1);
        }
        while (true) {
            for (int i = 1; i < task.length; i++) {
                c.printf("%d: %s\n", i, task[i].taskDescription());
            }
            c.printf("0: %s\n", task[0].taskDescription());
            input = c.readLine("Please choose a command from above: ");
            try {
                command = Integer.parseInt(input.trim());
                if (0 > command || task.length <= command) {
                    c.printf("Unfortunately, %d is not a valid command.  Please try again\n", command);
                } else {
                    c.printf("\n\n\n----------------------------------\n"); // To separate the task from the task selection
                    task[command].doTask(c, connection, statement);
                    c.printf("----------------------------------\n\n\n"); // To separate the task from the task selection
                }
            } catch (NumberFormatException e) {
                c.printf("Unfortunately, that is not a valid command.  Please try again.  We only accept integers up in here.\n");
            }
        }
    }

    public static void main(String args[]) {
        UISkeleton demo = new UISkeleton();
    }
}
